Add target-specific init options to all file formats.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 5 Nov 2002 06:08:52 +0000 (06:08 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 5 Nov 2002 06:08:52 +0000 (06:08 +0000)
Add 'baud' option to magproto.

24 files changed:
gpsbabel/README
gpsbabel/cetus.c
gpsbabel/csv.c
gpsbabel/defs.h
gpsbabel/dna.c
gpsbabel/garmin.c
gpsbabel/geo.c
gpsbabel/gpsman.c
gpsbabel/gpspilot.c
gpsbabel/gpsutil.c
gpsbabel/gpx.c
gpsbabel/holux.c
gpsbabel/magnav.c
gpsbabel/magproto.c
gpsbabel/main.c
gpsbabel/mapsend.c
gpsbabel/mapsource.c
gpsbabel/mxf.c
gpsbabel/ozi.c
gpsbabel/pcx.c
gpsbabel/psp.c
gpsbabel/tiger.c
gpsbabel/tpg.c
gpsbabel/vecs.c

index 68d86a1d9cfc2445326ab96491113ca07433b3f2..1fc27f08eeaa6d7c4fcc40b3a1307bdd4690e017 100644 (file)
@@ -58,6 +58,9 @@ THE FORMATS
        program.    Communication errors are handled and verification of
        data is turned on.
 
+       Additional options:
+       baud: may be 1200, 2400, 4800, 9600, 19200, but must match receiver.
+
     GARMIN
 
        Waypoint serial upload and download works reliably under both
index c6b2fe638e2ad1b13e99a6e659348be9f792cce0..64a94dab13ba4a7a4ce895376b78f313fe5d4b9a 100644 (file)
@@ -60,7 +60,7 @@ struct pdb *opdb;
 struct pdb_record *opdb_rec;
 
 static void
-rd_init(const char *fname)
+rd_init(const char *fname, const char *args)
 {
        file_in = fopen(fname, "rb");
        if (file_in == NULL) {
@@ -75,7 +75,7 @@ rd_deinit(void)
 }
 
 static void
-wr_init(const char *fname)
+wr_init(const char *fname, const char *args)
 {
        file_out = fopen(fname, "wb");
        out_fname = fname;
index 4950110399eb2786c502c36a313eade9c1af83db..e3d9cc01950ec336fa099f59fff41e72742225c8 100644 (file)
@@ -30,7 +30,7 @@ static FILE *file_out;
 #define MYNAME "CSV"
 
 static void
-rd_init(const char *fname)
+rd_init(const char *fname, const char *args)
 {
        file_in = fopen(fname, "r");
        if (file_in == NULL) {
@@ -45,7 +45,7 @@ rd_deinit(void)
 }
 
 static void
-wr_init(const char *fname)
+wr_init(const char *fname, const char *args)
 {
        file_out = fopen(fname, "w");
        if (file_out == NULL) {
@@ -54,9 +54,9 @@ wr_init(const char *fname)
 }
 
 static void
-xmap_wr_init(const char *fname)
+xmap_wr_init(const char *fname, const char *args)
 {
-       wr_init(fname);
+       wr_init(fname, args);
        fprintf(file_out, "BEGIN SYMBOL\n");
 }
 
index 6c8629a0e0a9b300f1c086e71609c4d4c4f4b038..20e020dc5880360a71c39ebfb1eba29a122f4de4 100644 (file)
@@ -78,7 +78,6 @@ typedef struct {
 
 extern global_options global_opts;
 
-
 /*
  * Extended data if waypoint happens to represent a geocache.  This is 
  * totally voluntary data...
@@ -144,10 +143,11 @@ typedef struct {
        int rte_num;
 } route_head;
 
-typedef void (*ff_init) (char const *);
+typedef void (*ff_init) (char const *, char const *);
 typedef void (*ff_deinit) (void);
 typedef void (*ff_read) (void);
 typedef void (*ff_write) (void);
+char * get_option(const char *iarglist, const char *argname);
 
 void fprintdms(FILE *, const coord *, int);
 
@@ -188,7 +188,7 @@ void fatal(const char *, ...)
        __attribute__ ((__format__ (__printf__, 1, 2)));
 #endif
        ;
-ff_vecs_t *find_vec(char *);
+ff_vecs_t *find_vec(char *, char **);
 void disp_vecs(void);
 void printposn(const coord *c, int is_lat);
 
index 10b0c699ef5b96db7c3386aecb18addb199704b2..54eb791bea4e1ae52e9ab64379137931532d159f 100644 (file)
@@ -32,7 +32,7 @@ static FILE *file_out;
 #define MYNAME "DNA"
 
 static void
-rd_init(const char *fname)
+rd_init(const char *fname, const char *args)
 {
        file_in = fopen(fname, "r");
        if (file_in == NULL) {
@@ -47,7 +47,7 @@ rd_deinit(void)
 }
 
 static void
-wr_init(const char *fname)
+wr_init(const char *fname, const char *args)
 {
        file_out = fopen(fname, "w");
        if (file_out == NULL) {
index b1df22a3725be773497f13e9a0c39c5b99326799..0ca73c40ea4ef4ff5c93c9bf7f976051b77f9e04 100644 (file)
@@ -27,7 +27,7 @@
 static const char *portname;
 
 static void
-rw_init(const char *fname)
+rw_init(const char *fname, const char *opts)
 {
         if (GPS_Init(fname) < 0) {
                fatal(MYNAME ":Can't init %s\n", fname);
index fe2467b8c7afe9d1e876c6754fd92d66cb17c198..5662cc24ff7fa1c5890d0836765e1c303f741ad5 100644 (file)
@@ -141,7 +141,7 @@ geo_cdata(void *dta, const XML_Char *s, int len)
 }
 
 void
-geo_rd_init(const char *fname)
+geo_rd_init(const char *fname, const char *args)
 {
        fd = fopen(fname, "r");
        if (fd == NULL) {
@@ -165,7 +165,7 @@ geo_rd_deinit(void)
 }
 
 void
-geo_wr_init(const char *fname)
+geo_wr_init(const char *fname, const char *args)
 {
        ofd = fopen(fname, "w");
        if (ofd == NULL) {
index fbabe1ebc209113ad87571ebec4a868003a0ff81..fc15d5be6139cafdda5ec30db01456b02acc2b59 100644 (file)
@@ -25,7 +25,7 @@ static FILE *out_file;
 #define MYNAME "GPSMAN"
 
 static void
-gpsman_rd_init(const char *fname)
+gpsman_rd_init(const char *fname, const char *args)
 {
        in_file = fopen(fname, "r");
        if (in_file == NULL) {
@@ -40,7 +40,7 @@ gpsman_rd_deinit(void)
 }
 
 static void
-gpsman_wr_init(const char *fname)
+gpsman_wr_init(const char *fname, const char *args)
 {
        out_file = fopen(fname, "w");
        if (out_file == NULL) {
index 80fa6749b24d7d021de290a182911d5a2cbb6c49..26a750149c3b61cfef50d4b6a87b8d137ac2a942 100644 (file)
@@ -41,7 +41,7 @@ struct pdb *opdb;
 struct pdb_record *opdb_rec;
 
 static void
-rd_init(const char *fname)
+rd_init(const char *fname, const char *args)
 {
        file_in = fopen(fname, "rb");
        if (file_in == NULL) {
@@ -56,7 +56,7 @@ rd_deinit(void)
 }
 
 static void
-wr_init(const char *fname)
+wr_init(const char *fname, const char *args)
 {
        file_out = fopen(fname, "wb");
        out_fname = fname;
index 19e1a06e6a53a6438d6656032f752c5267eeb9db..6d0dc3e28f8203c2bc4a493cb14ccf0c0ccf6184 100644 (file)
@@ -11,7 +11,7 @@ static FILE *file_out;
 #define MYNAME "GPSUTIL"
 
 static void
-rd_init(const char *fname)
+rd_init(const char *fname, const char *args)
 {
        file_in = fopen(fname, "r");
        if (file_in == NULL) {
@@ -26,7 +26,7 @@ rd_deinit(void)
 }
 
 static void
-wr_init(const char *fname)
+wr_init(const char *fname, const char *args)
 {
        file_out = fopen(fname, "w");
        if (file_out == NULL) {
index 5f332fe9952c6d7e0104cac20026da708872395d..44e20e0f6836a8ddf223a13065c4afc5759ffc14 100644 (file)
@@ -222,7 +222,7 @@ gpx_cdata(void *dta, const XML_Char *s, int len)
 }
 
 void
-gpx_rd_init(const char *fname)
+gpx_rd_init(const char *fname, const char *args)
 {
        fd = fopen(fname, "r");
        if (fd == NULL) {
@@ -244,7 +244,7 @@ gpx_rd_deinit(void)
 }
 
 void
-gpx_wr_init(const char *fname)
+gpx_wr_init(const char *fname, const char *args)
 {
        ofd = fopen(fname, "w");
        if (ofd == NULL) {
index 04fa7c3a03c204e1459f73ce9ab17f12b07c264f..42b8b303fa78a0d90d078266fd7b883eb96f180d 100644 (file)
@@ -37,7 +37,7 @@ static        unsigned char *HxWFile;
 static  char fOutname[256];
 
 
-static void rd_init(const char *fname)
+static void rd_init(const char *fname, const char *args)
 {
        file_in = fopen(fname, "rb");
        if (file_in == NULL) {
@@ -56,7 +56,7 @@ static void rd_deinit(void)
 
 
 static void
-wr_init(const char *fname)
+wr_init(const char *fname, const char *args)
 {
        HxWFile = xcalloc(GM100_WPO_FILE_SIZE, 1);
 
index 93de8a7ccb2d62f90b60868c35286cfaee2b0502..730d3cfc2bfed23323ddb374bfa9a7fadf2183cf 100644 (file)
@@ -56,7 +56,7 @@ struct pdb *opdb;
 struct pdb_record *opdb_rec;
 
 static void
-rd_init(const char *fname)
+rd_init(const char *fname, const char *args)
 {
        file_in = fopen(fname, "rb");
        if (file_in == NULL) {
@@ -71,7 +71,7 @@ rd_deinit(void)
 }
 
 static void
-wr_init(const char *fname)
+wr_init(const char *fname, const char *args)
 {
        file_out = fopen(fname, "wb");
        out_fname = fname;
index b1d6b1efc03349560feb610ee2f4e85c33bf71a8..4d04a858faf1f690952bb2c48d67b6ae9c6565fe 100644 (file)
@@ -27,7 +27,7 @@
 #include "defs.h"
 #include "magellan.h"
 
-#define BAUDRATE B4800
+int bitrate = 4800;
 #define MYNAME "MAGPROTO"
 
 #if __WIN32__
@@ -406,6 +406,19 @@ mag_readmsg(void)
 
 #include <windows.h>
 
+DWORD 
+mkspeed(bitrate)
+{
+       switch (bitrate) {
+               case 1200: return CBR_1200;
+               case 2400: return CBR_2400;
+               case 4800: return CBR_4800;
+               case 9600: return CBR_9600;
+               case 19200: return CBR_19200;
+               default: return CBR_4800;
+       }
+}
+
 HANDLE comport;
 
 static
@@ -430,7 +443,7 @@ terminit(const char *portname)
        }
        tio.DCBlength = sizeof(DCB);
        GetCommState (comport, &tio);
-       tio.BaudRate = CBR_4800;
+       tio.BaudRate = mkspeed(bitrate);
        tio.fBinary = TRUE;
        tio.fParity = TRUE;
        tio.fOutxCtsFlow = FALSE;
@@ -510,6 +523,20 @@ termdeinit()
 
 #include <termios.h>
 
+speed_t 
+mkspeed(unsigned br)
+{
+       switch (br) {
+               case 1200: return B1200;
+               case 2400: return B2400;
+               case 4800: return B4800;
+               case 9600: return B9600;
+               case 19200: return B19200;
+               default: return B4800;
+       }
+}
+
+
 static struct termios orig_tio;
 static void
 terminit(const char *portname)
@@ -547,8 +574,8 @@ terminit(const char *portname)
        new_tio.c_cc[VTIME] = 10;
        new_tio.c_cc[VMIN] = 0;
 
-       cfsetospeed(&new_tio, BAUDRATE);
-       cfsetispeed(&new_tio, BAUDRATE);
+       cfsetospeed(&new_tio, mkspeed(bitrate));
+       cfsetispeed(&new_tio, mkspeed(bitrate));
        tcsetattr(magfd, TCSAFLUSH, &new_tio);
 }
 
@@ -575,9 +602,14 @@ termwrite(char *obuf, int size)
 
 
 static void
-mag_rd_init(const char *portname)
+mag_rd_init(const char *portname, const char *args)
 {
        time_t now, later;
+       char * bs = get_option(args, "baud");
+
+       if (bs) {
+               bitrate=atoi(bs);
+       }
 
        terminit(portname);
        
@@ -603,7 +635,7 @@ mag_rd_init(const char *portname)
 }
 
 static void
-mag_wr_init(const char *portname)
+mag_wr_init(const char *portname, const char *args)
 {
        struct stat sbuf;
 
@@ -622,7 +654,7 @@ mag_wr_init(const char *portname)
                 *  reading and writing, so we let rd_init do the dirty work.
                 */
                fclose(magfile_out);
-               mag_rd_init(portname);
+               mag_rd_init(portname, args);
        }
 }
 
index daa37bde5f9332545fcc4bfc31682e48a7645cd9..10f764efef255313d1a1a913183625572c2af2c8 100644 (file)
@@ -41,6 +41,8 @@ main(int argc, char *argv[])
        ff_vecs_t *ovecs = NULL;
        char *fname = NULL;
        char *ofname = NULL;
+       char *ivec_opts = NULL;
+       char *ovec_opts = NULL;
 
        waypt_init();
        route_init();
@@ -65,11 +67,11 @@ main(int argc, char *argv[])
 
                switch (c) {
                        case 'i': 
-                               ivecs = find_vec(optarg);
+                               ivecs = find_vec(optarg, &ivec_opts);
                                argn++;
                                break;
                        case 'o':
-                               ovecs = find_vec(optarg);
+                               ovecs = find_vec(optarg, &ovec_opts);
                                argn++;
                                break;
                        case 'f':
@@ -78,7 +80,7 @@ main(int argc, char *argv[])
                                if (ivecs == NULL) {
                                        fatal ("No valid input type specified");
                                }
-                               ivecs->rd_init(fname);
+                               ivecs->rd_init(fname, ivec_opts);
                                ivecs->read();
                                ivecs->rd_deinit();
                                break;
@@ -86,7 +88,7 @@ main(int argc, char *argv[])
                                ofname = optarg;
                                argn++;
                                if (ovecs) {
-                                       ovecs->wr_init(ofname);
+                                       ovecs->wr_init(ofname, ovec_opts);
                                        ovecs->write();
                                        ovecs->wr_deinit();
                                }
index 01df1b072ca8a267f059755a861dcc5a12d5bbe1..3fdbe822480474837031ab7cc68406d46411108a 100644 (file)
@@ -48,7 +48,7 @@ test_endianness(void)
 }
 
 static void
-mapsend_rd_init(const char *fname)
+mapsend_rd_init(const char *fname, const char *args)
 {
        mapsend_file_in = fopen(fname, "rb");
        if (mapsend_file_in == NULL) {
@@ -164,7 +164,7 @@ my_fwrite4(void *ptr, FILE *stream)
 }
 
 static void
-mapsend_wr_init(const char *fname)
+mapsend_wr_init(const char *fname, const char *args)
 {
        mapsend_file_out = fopen(fname, "wb");
        if (mapsend_file_out == NULL) {
index 3db7d2d1e1432b1c304c4936024b747a6b32108b..492238351e1505952a2d8df403c0b99146c553e8 100644 (file)
@@ -30,7 +30,7 @@ static FILE *mapsource_file_out;
 #define MYNAME "MAPSOURCE" 
 
 static void
-mapsource_rd_init(const char *fname)
+mapsource_rd_init(const char *fname, const char *args)
 {
        mapsource_file_in = fopen(fname, "r");
        if (mapsource_file_in == NULL) {
@@ -45,7 +45,7 @@ mapsource_rd_deinit(void)
 }
 
 static void
-mapsource_wr_init(const char *fname)
+mapsource_wr_init(const char *fname, const char *args)
 {
        mapsource_file_out = fopen(fname, "w");
        if (mapsource_file_out == NULL) {
index e2e25e1483b3ee9de496fffa691ef86aa33092ce..db20ccb131f2141034256a449985229daa2dcebc 100644 (file)
@@ -38,7 +38,7 @@ static FILE *file_in;
 static FILE *file_out;
 
 static void 
-rd_init(const char *fname)
+rd_init(const char *fname, const char *args)
 {
     file_in = fopen(fname, "r");
     if (file_in == NULL) {
@@ -53,7 +53,7 @@ rd_deinit(void)
 }
 
 static void 
-wr_init(const char *fname)
+wr_init(const char *fname, const char *args)
 {
     file_out = fopen(fname, "w");
     if (file_out == NULL) {
index 3ef4ac262c5cec0a4a2aa4a461018aae1742ac7e..b04d05dac16264b1cbc380a813002ab9a81ba440 100644 (file)
@@ -36,7 +36,7 @@ static FILE *file_in;
 static FILE *file_out;
 
 static void 
-rd_init(const char *fname)
+rd_init(const char *fname, const char *args)
 {
     file_in = fopen(fname, "r");
     if (file_in == NULL) {
@@ -51,7 +51,7 @@ rd_deinit(void)
 }
 
 static void 
-wr_init(const char *fname)
+wr_init(const char *fname, const char *args)
 {
     file_out = fopen(fname, "w");
     if (file_out == NULL) {
index 039e1b2ef61a21333f28181d98c132aa6a113f9b..cb81973e448066f458e398bd9db1108805f96d94 100644 (file)
@@ -29,7 +29,7 @@ static FILE *file_out;
 
 
 static void
-rd_init(const char *fname)
+rd_init(const char *fname, const char *args)
 {
        file_in = fopen(fname, "r");
        if (file_in == NULL) {
@@ -44,7 +44,7 @@ rd_deinit(void)
 }
 
 static void
-wr_init(const char *fname)
+wr_init(const char *fname, const char *args)
 {
        file_out = fopen(fname, "w");
        if (file_out == NULL) {
index ea2e085ba43e0f7006e0d754b335c435ff66df3e..3e86092663bbb6076c3f0d77efccc586461b54b1 100644 (file)
@@ -241,7 +241,7 @@ buffer_washer(char * buff, int buffer_len)
 }
 
 static void
-psp_rd_init(const char *fname)
+psp_rd_init(const char *fname, const char *args)
 {
        psp_file_in = fopen(fname, "rb");
        if (psp_file_in == NULL) {
@@ -256,7 +256,7 @@ psp_rd_deinit(void)
 }
 
 static void
-psp_wr_init(const char *fname)
+psp_wr_init(const char *fname, const char *args)
 {
        psp_file_out = fopen(fname, "wb");
        if (psp_file_out == NULL) {
index faf5efb0d49d0bc5469aae30bb63dafb59ad4808..d56c1832fa9d701ab205f4dcba5be3fcd8250641 100644 (file)
@@ -28,7 +28,7 @@ static FILE *file_out;
 #define MYNAME "GPSUTIL"
 
 static void
-rd_init(const char *fname)
+rd_init(const char *fname, const char *args)
 {
        file_in = fopen(fname, "r");
        if (file_in == NULL) {
@@ -43,7 +43,7 @@ rd_deinit(void)
 }
 
 static void
-wr_init(const char *fname)
+wr_init(const char *fname, const char *args)
 {
        file_out = fopen(fname, "w");
        if (file_out == NULL) {
index d7dd62c11c030b22d3b494f2d40d8a10ed4d0b1b..dc005a38335b3f96dba1d4606c00e2f25b448ccc 100644 (file)
@@ -128,7 +128,7 @@ valid_tpg_header(char * header, int len)
 }
 
 static void
-tpg_rd_init(const char *fname)
+tpg_rd_init(const char *fname, const char *args)
 {
        tpg_file_in = fopen(fname, "rb");
        if (tpg_file_in == NULL) {
@@ -143,7 +143,7 @@ tpg_rd_deinit(void)
 }
 
 static void
-tpg_wr_init(const char *fname)
+tpg_wr_init(const char *fname, const char *args)
 {
        tpg_file_out = fopen(fname, "wb");
        if (tpg_file_out == NULL) {
index 25d161cd24c1f0242e72c5dfb677664e596779d3..9f7bfd6f90051617a3f7465f5c73e906717d8c86 100644 (file)
@@ -166,18 +166,66 @@ vecs_t vec_list[] = {
 };
 
 ff_vecs_t *
-find_vec(char *const vecname)
+find_vec(char *const vecname, char **opts)
 {
        vecs_t *vec = vec_list;
+       char *v = xstrdup(vecname);
+       char *svecname = strtok(v, ",");
+
        while (vec->vec) {
-               if (strcmp(vecname, vec->name) == 0) {
+               if (strcmp(svecname, vec->name) == 0) {
+                       char * res = strchr(vecname, ',');
+                       if (res)
+                               *opts = strchr(vecname, ',')+1;
+                       else
+                               *opts = NULL;
+                       free(v);
                        return vec->vec;
                }
                vec++;
        }
+       free(v);
        return NULL;
 }
 
+/*
+ * Find and return a specific argument in an arg list.
+ * Modelled approximately after getenv.
+ */
+char *
+get_option(const char *iarglist, const char *argname)
+{
+       size_t arglen = strlen(argname);
+       char *arglist;
+       char *rval = NULL;
+       char *arg;
+       char *argp;
+
+       if (!iarglist) {
+               return NULL;
+       }
+
+       arglen = strlen(argname);
+       arglist = xstrdup(iarglist);
+
+       for (arg = arglist; argp = strtok(arg, ","); arg = NULL) {
+               if (0 == strncmp(argp, argname, arglen)) {
+                       /*
+                        * If we have something of the form "foo=bar"
+                        * return "bar".   Otherwise, we assume we have
+                        * simply "foo" so we return that.
+                        */
+                       if (argp[arglen] == '=')
+                               rval = argp + arglen + 1;
+                       else
+                               rval = argp;
+                       break;
+               }
+       }
+       free(arglist);
+       return rval;
+}
+
 void
 disp_vecs(void)
 {